/*    */ package com.hp.bon.sgw.scsp;
/*    */ 
/*    */ import org.apache.mina.core.buffer.IoBuffer;
/*    */ import org.apache.mina.core.session.IoSession;
/*    */ import org.apache.mina.filter.codec.ProtocolEncoderOutput;
/*    */ import org.apache.mina.filter.codec.demux.MessageEncoder;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ 
/*    */ public class SCSPMessageEncoder<T extends SCSPMessage>
/*    */   implements MessageEncoder<T>
/*    */ {
/* 36 */   private static final Logger LOGGER = LoggerFactory.getLogger(SCSPMessageEncoder.class);
/*    */ 
/*    */   public void encode(IoSession session, T message, ProtocolEncoderOutput out) throws Exception
/*    */   {
/* 40 */     byte[] bodyArray = message.getBodyArray();
/* 41 */     if (bodyArray == null)
/*    */     {
/* 43 */       bodyArray = message.getBodyStr().getBytes("UTF-8");
/*    */     }
/* 45 */     int bodyLength = bodyArray.length;
/*    */ 
/* 47 */     IoBuffer buf = IoBuffer.allocate(16);
/* 48 */     buf.setAutoExpand(true);
/* 49 */     buf.putInt(bodyLength + 8);
/* 50 */     buf.put(SCSPMessage.VERSION);
/* 51 */     buf.put((byte)0);
/* 52 */     buf.putChar('\000');
/* 53 */     buf.put(bodyArray);
/* 54 */     buf.flip();
/* 55 */     out.write(buf);
/* 56 */     LOGGER.debug("send msg:" + message.getBodyStr());
/*    */   }
/*    */ }

/* Location:           C:\Users\think\Desktop\sgw_2.1.jar
 * Qualified Name:     com.hp.bon.sgw.scsp.SCSPMessageEncoder
 * JD-Core Version:    0.6.1
 */